package constraint;

import geometry.Geometry;
import graph.AbstractNode;
import graph.GNode;
import graph.NodeType;

public class Variable extends AbstractNode implements GNode {
    private VariableType type;
    private Geometry geometry;
    private Domain domain;
    
    public Variable(double lowerBound, double upperBound, VariableType type, Geometry geometry, String name) {
        super(NodeType.DETAIL, type.toString());
        domain = new RealDomain(lowerBound, upperBound);
        this.geometry = geometry;
        this.type = type;
    }
    
    public Variable(double singletonValue, VariableType type, Geometry geometry, String name) {
        super(NodeType.DETAIL, type.toString());
        domain = new RealDomain(singletonValue);
        this.geometry = geometry;
        this.type = type;
    }

    public boolean isSingleton() {
        return domain.isSingleton();
    }

    public double getDoubleValue() {
        return getIntValue();
    }
    
    public float getFloatValue() {
        return getIntValue();
    }

    public int getIntValue() {
        if (isSingleton()==false) {
            System.out.println("GETTING VALUE FOR VARIABLE THAT IS NOT SINGLETON");
        }
        return domain.value();
    }
        
    public String toString() {
        if (isSingleton()) {
            return String.valueOf(getIntValue());   
        }
        return domain.toString();
    }

    public GNode copy() {
        // TODO Auto-generated method stub
        return null;
    }

    public void setValue(double value) {
        domain = new RealDomain(value);
    }
    
    public void setDomain(double min, double max) {
        domain = new RealDomain(min, max);
    }

    public Constraint greaterThan(Variable var) {
        return new ConstraintGreaterThan(this, var);
    }

    public Constraint lessThan(Variable var) {
        return new ConstraintLessThan(this, var);
    }
    
    public Constraint equalTo(Variable var) {
        return new ConstraintEquals(this, var);
    }
}
